package cn.yi.newsys.service.impl;

import java.util.List;

import cn.yi.newsys.dao.CommentDao;
import cn.yi.newsys.dao.impl.CommentDaoImpl;
import cn.yi.newsys.pojo.Comment;
import cn.yi.newsys.pojo.PageBean;
import cn.yi.newsys.service.CommentService;

/**
 * 评论业务逻辑实现类
 * @author Lenovo
 *
 */
public class CommentServiceImpl implements CommentService{

	private CommentDao cd = new CommentDaoImpl();
	


	@Override
	public boolean save(Comment com) {
		int row = cd.save(com);
		if(row == 0){
			return false ;
		}else{
			return true ;
		}
	}


	@Override
	public int totalComment(int nid) {
		return cd.getTotalComment(nid) ;
	}


	@Override
	public PageBean<Comment> getCommentByNid(int pageNo, int pageSize, int nid) {
		// 计算偏移量
		int offset = (pageNo - 1) * pageSize ;
		// 创建 pageBean 对象
		PageBean<Comment> pb = new PageBean<Comment>() ;
		pb.setCurrPageNo(pageNo) ;
		List<Comment> list = cd.queryCommentByNewsID(nid, offset, pageSize) ;
		pb.setLisr(list) ;
		pb.setPageSize(pageSize) ;
		pb.setTotalCount(this.totalComment(nid)) ;
		return pb ;
	}

}
